
$(function() {


	// init date tables
	var jobTable = $("#procedure_log_list").dataTable({
		"deferRender": true,
		"processing" : true,
	    "serverSide": true,
		"ajax": {
			url: base_url + "/procedure/etlHisPageList",
			type:"post",
	        data : function ( d ) {
	        	var obj = {};
                obj.PROCEDURE_NAME = $('#PROCEDURE_NAME').val();
				obj.START_TIME = $('#START_TIME').val();
				obj.END_TIME = $('#END_TIME').val();
	        	obj.start = d.start ;
	        	obj.length = d.length ;
                return obj;
            }
	    },
	    "searching": false,
	    "ordering": false,
	    //"scrollX": true,	// X轴滚动条，取消自适应
	    "columns": [
	                {

	                	"data": 'OBJ_ID',
						"visible" : true,
						"width":'8%'
					},
	                {

						"data": 'PROCEDURE_NAME',
	                	"visible" : true,
						"width":'20%',
            		},
	                {

	                	"data": 'START_TIME',
						"visible" : true,
						"width":'20%',
						"render": function ( data, type, row ) {
							return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
						}
					},
					{

						"data": 'END_TIME',
						"width":'20%',
						"render": function ( data, type, row ) {
							return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
						}
					},
	                {

						"data": 'ROWCOUNT', "visible" : true,
						"width":'10%',

					},

	                {

						"data": 'RUN_TIME',
	                	"visible" : true,
						"width":'10%',
	                	"render": function ( data, type, row ) {
	                		return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
	                	}
	                },
	                {
						"data": 'EXECUTE_DESC',
						"width":'15%' ,
						"visible" : true
	                }
	            ],
		"language" : {
			"sProcessing" : "处理中...",
			"sLengthMenu" : "每页 _MENU_ 条记录",
			"sZeroRecords" : "没有匹配结果",
			"sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页，_TOTAL_ 条记录 )",
			"sInfoEmpty" : "无记录",
			"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix" : "",
			"sSearch" : "搜索:",
			"sUrl" : "",
			"sEmptyTable" : "表中数据为空",
			"sLoadingRecords" : "载入中...",
			"sInfoThousands" : ",",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上页",
				"sNext" : "下页",
				"sLast" : "末页"
			},
			"oAria" : {
				"sSortAscending" : ": 以升序排列此列",
				"sSortDescending" : ": 以降序排列此列"
			}
		}
	});

    // table data
    var tableData = {};

	// 搜索按钮
	$('#searchBtn').on('click', function(){
		jobTable.fnDraw();
	});

	$("#deleteLot").on("click",function(){

		layer.confirm('确认是否按照查询条件清理日志?', {icon: 3, title:'系统提示'}, function(index){
			layer.close(index);
			$.ajax({
				url: base_url + "/procedure/deleteEtlHis",
				type: "post",
				data: (function () {
					var obj = {};
					obj.PROCEDURE_NAME = $('#PROCEDURE_NAME').val();
					obj.START_TIME = $('#START_TIME').val();
					obj.END_TIME = $('#END_TIME').val();
					return obj;
				})(),
				dataType : "json",
				success : function(data){
					if (data.code == 200) {
						layer.open({
							title: '系统提示',
							content:   "日志清理成功",
							icon: '1',
							end: function(layero, index){
								if (true) {
									//window.location.reload();
									jobTable.fnDraw();
								}
							}
						});
					} else {
						layer.open({
							title: '系统提示',
							content: (data.msg ||    "日志清理失败"),
							icon: '2'
						});
					}
				}
			});
		});
	});

	$('input[dateFlag="Y"]').daterangepicker({
			singleDatePicker: true,
			showDropdowns: true,
			autoUpdateInput: false,
			timePicker24Hour : true,
			timePicker : true,
			timePickerSeconds:true,
			"locale": {
				format: 'YYYY-MM-DD HH:mm:ss',
				applyLabel: "应用",
				cancelLabel: "取消",
				resetLabel: "重置",
				daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
				monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
					                  '七月', '八月', '九月', '十月', '十一月', '十二月'
					        ]
			}
		},
		function(start, end, label) {
			beginTimeTake = start;
			if(!this.startDate){
				this.element.val('');
			}else{
				this.element.val(this.startDate.format(this.locale.format));
			}
		});

});


